package cn.tedu.test.luban.starter.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Random;

public class OSCondition implements Condition {
    //判断条件是否满足的逻辑
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        String property = environment.getProperty("os.name");
        System.out.println("当前操作系统的名字"+property);
        if (property.contains("Linux")){
            //条件满足
            System.out.println("操作系统的条件要求 满足");
            return true;
        }
        //条件不满足
        System.out.println("操作系统的条件要求 不满足");
        return false;
    }
}
